import axios from "axios";
import { message } from 'ant-design-vue';

const request = axios.create({
    baseURL: 'http://192.168.245.244:8101/',
    timeout: 5000,
    withCredentials: true
})

// 响应拦截器
request.interceptors.response.use(res => {
    if (res.status !== 200){
        message.error('系统内部异常')
        return res
    }else {
        if (res.data.code !== 0){
            message.error(res.data.message)
            return res
        }
    }
    return res
}, err => {
    message.error('系统内部异常')
    return Promise.reject(err)
})
//请求
request.interceptors.request.use(res => {
    const token = localStorage.getItem('token');
    if (token){
        res.headers['Authorization'] = token
    }
    return res
}, err => {
    message.error('系统内部异常')
    return Promise.reject(err)
})
export default request
